using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_DeliveryTypes : System.Web.UI.UserControl
{
    processDeliveryType pDelivery;
    protected void Page_Load(object sender, EventArgs e)
    {
        pDelivery = new processDeliveryType();
        if (!Page.IsPostBack)
        {
            Load_gvwDelivery();
        }
    }
    private void Load_gvwDelivery()
    {
        gvwDelivery.DataSource = pDelivery.getDeliveryType();
        gvwDelivery.DataBind();
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        string DeliveryTypeID = pDelivery.getDeliveryTypeID();
        if (pDelivery.insertDeliveryType(DeliveryTypeID, "") > 0)
        {
            gvwDelivery.EditIndex = gvwDelivery.Rows.Count;
            Load_gvwDelivery();
        }
    }
    protected void gvwDelivery_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {

    }
    protected void gvwDelivery_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string DeliveryTypeID = gvwDelivery.DataKeys[e.RowIndex].Value.ToString();
        string DeliveryTypeName = ((TextBox)gvwDelivery.Rows[e.RowIndex].Cells[1].Controls[0]).Text;

        if (pDelivery.updateDeliveryType(DeliveryTypeID, DeliveryTypeName) > 0)
        {
            gvwDelivery.EditIndex = -1;
            Load_gvwDelivery();
        }
    }
    protected void gvwDelivery_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvwDelivery.EditIndex = e.NewEditIndex;
        Load_gvwDelivery();

    }
    protected void gvwDelivery_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            string DeliveryTypeID = gvwDelivery.DataKeys[e.RowIndex].Value.ToString();
            if (pDelivery.deleteDeliveryType(DeliveryTypeID) > 0)
            {
                Alert.Show("This DeliveryType type is being used, you can not delete!");
                Load_gvwDelivery();
            }
        }
        catch (Exception)
        {
            Alert.Show("This DeliveryType type is being used, you can not delete!");
        }  

    }
    protected void gvwDelivery_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvwDelivery.EditIndex = -1;
        Load_gvwDelivery();

    }
    protected void gvwDelivery_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvwDelivery.PageIndex = e.NewPageIndex;
        Load_gvwDelivery();
    }
}
